/*This file is part of AENIMA. AENIMA is a module of BCI++ framework for the implementation of brain computerinterface systems. 
AEnima is intended for use with BCI++ only.

BCI++ is a project of the Sensibilab of the Politecnico di Milano. 

AENIMA is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as 
published by the Free Software Foundation, either version 3 of 
the License, or (at your option) any later version.

AENIMA is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU General Public License
and the GNU Lesser General Public License along with AENIMA.  
If not, see <http://www.gnu.org/licenses/>.*/

/*!
	\file	myserial.h
	 \b Myserial library for the serial communication with BTicino L4686SDK 

	\author	Paolo Perego E-Mail: info.sensibilab@polimi.it 

	\date	2007-09-06 creation \n
		2009-01-28 last modification

	\b COPYRIGHT: 
		This program is property of Sensibilab - Campus Ponit - Lecco
*/


#include "wx/ctb/getopt.h"
#if ( GPIB )
# include "wx/ctb/gpib.h"
#endif
#include "wx/ctb/iobase.h"
#include "wx/ctb/serport.h"
#include "wx/ctb/timer.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/*!\fn int init_serial(char *devname, wxBaud baudrate)
Function for the initialization of the serial port: the function opens the communication 
with the serial port given the name port and the baudrate.\n
The function sets automatically the line DTR = +Vcc e RTS = -Vcc as the setting preference 
of the SCS-OPEN L4686SDK device.
The function return 0 if the communication is open, -1 if there is an error.
\param *devname Name of the serial port (COM1, COM"...)\n
es.: if the port is COM1, devname = wxCOM1
\param baudrate Speed of the serial port\n
es.: 115200, baudrate = wxBAUD_115200*/
int init_serial(char *devname, wxBaud baudrate);
/*!\fn void close_serial()
Function to close the serial port communication*/
void close_serial();
/*!\fn int serial_write (char *comando);
Function to write a string on the serial port.
The function return 0 if the writing operation was correct, -1 if there was an error.
\param *comando It is the OPENWEBNET command to write on the serial\n
It is composed by:\n
*CHI*COSA*DOVE## command;\n
*#CHI*DOVE## read device state.\n\n
es.1: Turn on light 12 --> *1*1*12##\n
es.2: Read state of light 22: *#1*22##.*/
int serial_write (char *comando);
/*!\fn int serial_read (char* buf, size_t dim_stringa)
This function reads a string of chars of a given length. If nothing is read for more than a second,
the read state is interrupted ad an error was given.\n
The function returns the number of chars that has been read. If there was an error, the function returns -1.\n
\param buf It is the pointer to the reading array
\param dim_stringa Number of chars to be read*/
int serial_read (char* buf, size_t dim_stringa);
/*!\fn void clean_buffer (void)
Clean the read buffer of the serial port.*/
void clean_buffer (void);